module Fighter {
	/**
	 * 带护盾的飞机子类---刘伟 
	 * */
	export class PlaneShield extends BasicFly {

		/**护盾 */
		public Shield: egret.Shape;
		/**护盾半径 */
		public Shield_r: number;
		/**护盾计时器 */
		private Shield_time: number = 0;
		public create() {
			super.create();
			this.drawShield();
		}
		public update(deltaTimeStamp) {

			super.update(deltaTimeStamp);
			this.moveShield(deltaTimeStamp);
		}

		/**绘制护盾 */
		protected drawShield() {
			if (this.Shield == null) {
				this.Shield = new egret.Shape();
				this.Shield_r = this.fly.height * 4;
				this.Shield.graphics.beginFill(0x000000, 0.5);
				this.Shield.graphics.drawCircle(this.fly.width / 2, this.fly.height / 2, this.Shield_r);
				this.Shield.graphics.endFill();
			}

		}
		/**护盾移动 */
		protected moveShield(deltaTimeStamp) {
			this.Shield.x = this.fly.x;
			this.Shield.y = this.fly.y;
			this.Shield_time += deltaTimeStamp;
			if (this.Shield_time >= 1000) {
				this.shieldWork();
				this.Shield_time = 0;
			}
		}
		/**护盾的开启与关闭 */
		protected shieldWork() {
			if (!this.Shield.visible) {
				this.Shield.visible = true;
			}
			else {
				this.Shield.visible = false;
			}
		}
		/**重写出生方法 */
		public born(point: egret.Point, tid)
		{
			super.born(point, tid);
			this.showPanle.addChild(this.Shield);

		}
		/**飞机飞出舞台 */
		public overLine() {
			super.overLine();
			if(this.showPanle && this.Shield.$hasAddToStage)
			{
				this.showPanle.removeChild(this.Shield);
			}
		}
		/**重写销毁方法 */
		public destroy()
		{
			super.destroy();
			if(this.showPanle && this.Shield.$hasAddToStage)
			{
				this.showPanle.removeChild(this.Shield);
			}
		}
		/**飞机与子弹的碰撞 */
		protected hittedByBullet() {
			super.hittedByBullet();
			if (this.showPanle.BulletManager) {
				let bulletList: any[] = this.showPanle.BulletManager.productBulletus;
				for (let i = 0; i < bulletList.length; i++) {
					let Tbullet: Bullet.BasicBullet = bulletList[i];
					let distance = egret.Point.distance(new egret.Point(this.fly.x,this.fly.y),new egret.Point(Tbullet.bullet.x,Tbullet.bullet.y));
					if (this.Shield.visible && distance<=this.Shield_r) {
						Tbullet.bulletHp--;
					}
				}
			}
		
		}

	}




}
